const path = require("path");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { InjectManifest } = require("workbox-webpack-plugin");
const FaviconsWebpackPlugin = require("favicons-webpack-plugin");

module.exports = {
    entry: ["./src/scripts/game.js", "./webpack/credits.js"],
    output: {
        path: path.resolve(__dirname, "../dist"),
        filename: "[name].bundle.js",
        chunkFilename: "[name].chunk.js",
    },
    resolve: {
        extensions: [".js"],
        alias: {
            Assets: path.resolve(__dirname, "../src/assets/"),
            Scripts: path.resolve(__dirname, "../src/scripts/"),
        },
    },
    module: {
        rules: [
            { test: /\.js$/, exclude: /node_modules/, loader: "babel-loader" },
            { test: /\.(png|jpe?g|gif)$/i, loader: "file-loader" },
        ],
    },
    optimization: {
        splitChunks: {
            cacheGroups: {
                commons: {
                    test: /[\\/]node_modules[\\/]/,
                    name: "vendors",
                    chunks: "all",
                    filename: "[name].bundle.js",
                },
            },
        },
    },
    plugins: [
        new HtmlWebpackPlugin({
            gameName: "GAMBIT",
            template: "src/index.html",
        }),
        new FaviconsWebpackPlugin("./src/assets/img/spiral.png"),
    ],
};
